package com.winning.juc;

import java.util.concurrent.atomic.AtomicInteger;

public class TestVolatileDemo {

    public static void main(String[] args) {

        VolatileDemo volatileDemo = new VolatileDemo();
        new Thread(volatileDemo).start();

        while(true){
            if(volatileDemo.isFlag()){
                System.out.println("-------------------");
                break;
            }
        }

    }

}

class VolatileDemo implements Runnable{

    private volatile boolean flag = false;

    @Override
    public void run() {

        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        flag = true;
        System.out.println("=========================");

    }

    public boolean isFlag() {
        return flag;
    }

    public void setFlag(boolean flag) {
        this.flag = flag;
    }
}
